<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="box">
    <p>状态：{{ state | toChina("hi","210") }}</p>
    <input type="button" value="修改状态" @click="changeState">
  </div>

  <script src="./js/vue.js"></script>
  <script>
    /* // 定义全局过滤器
    Vue.filter("toChina",function(value,a,b){
      // 分为三种情况
      switch(value){
        case 0: return "未处理";
        case 1: return "处理中";
        case 2: return "已处理";
        default: return "状态未知（状态异常）"
      }
    });

    let a = new Vue({
      el: "#box",
      data: {
        state:0
      },

      methods:{
        changeState(){
          this.state = 1;
        }
        }
    }); */

    // 定义局部过滤器
    let a = new Vue({
      el: "#box",
      data: {
        state:0
      },

      filters:{
        "toChina":function(value,a,b){
        console.log("过滤器被调用了",a,b);
          switch(value){
            case 0:return "未处理";
            case 1:return "处理中";
            case 2:return "已处理";
            default:return "状态未知（状态异常）"
          }
        }
      },

      methods:{
        changeState(){
          this.state = 1;
        }
      }
    })
    
  </script>
</body>
</html>